from typing import Optional, List
from pydantic import BaseModel, Field
from datetime import datetime


class ServerCreate(BaseModel):
    name: str
    host: str
    port: int = 22
    username: str
    password: str = Field(min_length=0, default="")
    description: Optional[str] = None


class ServerRead(BaseModel):
    id: int
    name: str
    host: str
    port: int
    username: str
    description: Optional[str] = None


class ServerUpdate(BaseModel):
    name: Optional[str] = None
    host: Optional[str] = None
    port: Optional[int] = None
    username: Optional[str] = None
    password: Optional[str] = None
    description: Optional[str] = None


class LogSummary(BaseModel):
    id: int
    server_id: int
    started_at: datetime
    ended_at: Optional[datetime]
    bytes_count: int


class LogDetail(BaseModel):
    id: int
    server_id: int
    started_at: datetime
    ended_at: Optional[datetime]
    bytes_count: int
    content: str


class SettingsRead(BaseModel):
    log_level: str
    ssh_timeout_seconds: int
    ssh_keepalive_seconds: int
    ws_heartbeat_seconds: int
    log_flush_threshold_bytes: int
    log_retention_days: int


class SettingsUpdate(BaseModel):
    log_level: Optional[str] = None
    ssh_timeout_seconds: Optional[int] = None
    ssh_keepalive_seconds: Optional[int] = None
    ws_heartbeat_seconds: Optional[int] = None
    log_flush_threshold_bytes: Optional[int] = None
    log_retention_days: Optional[int] = None

